#include<bits/stdc++.h>
#define all(a) a.begin(), a.end()
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

//std::mt19937 rng {std::chrono::steady_clock::now().time_since_epoch().count()};

int main() {
	
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	int n;
	std::cin >> n;
	std::vector<int> a(n);
	for(int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	int cnt = n;
	int ans = 0;
	while(cnt >= 2) {
		std::sort(all(a), std::greater());
		a[0]--;
		a[1]--;
		if(a[0] <= 0) {
			cnt--;
		}
		if(a[1] <= 0) {
			cnt--;
		}
		ans++;
	}
	std::cout << ans;


	return 0;
}